package com.sofwin.interceptor;


import com.ruoyi.common.core.utils.JwtUtils;
import com.ruoyi.common.core.utils.StringUtils;
import io.jsonwebtoken.Claims;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;

public class TestInterceptor implements HandlerInterceptor {
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception {
            Object user = request.getSession().getAttribute("user");
            if(StringUtils.isEmpty(user.toString())){
                response.sendRedirect("/*/login");
                return false;
            }
            // 如果返回 true，则继续执行下一个拦截器或处理器；如果返回 false，则中断请求
            return true;
        }










//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception {
//        Object user = request.getSession().getAttribute("user");
//
////        String token = request.getHeader("Authorization");
//        if(user!=null && StringUtils.isNotEmpty(user.toString())){
////            Claims parseToken = JwtUtils.parseToken(token);
////            response.setHeader("token", String.valueOf(parseToken));
//            // 如果返回 true，则继续执行下一个拦截器或处理器；如果返回 false，则中断请求
//            return true;
//        }
//        return false;
//    }
}




